package com.cfuture08.home.action.user;

import com.cfuture08.eweb4j.component.dwz.DWZUtil;
import com.cfuture08.eweb4j.mvc.action.ActionSupport;
import com.cfuture08.eweb4j.orm.dao.DAO;
import com.cfuture08.home.vo.User;

public class ChangePassword extends ActionSupport {
	private String newPassword;
	private String rePassword;
	private User user;

	public String execute() {
		if (newPassword.equals(rePassword)) {
			if (DAO.selectOne(user, new String[] { "id", "password" }) != null) {
				user.setPassword(newPassword);
				out.print(DAO.update(user, new String[]{"password"}) == true ? DWZUtil
								.getSuccessJson("修改密码成功", "", "", "") : DWZUtil
								.getFailedJson("修改密码失败"));
			}else{
				out.print(DWZUtil.getFailedJson("修改密码失败,旧密码输入错误"));
			}
		} else {
			out.print(DWZUtil.getFailedJson("修改密码失败,两次输入密码不一致"));
		}
		
		return AJAX;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String getRePassword() {
		return rePassword;
	}

	public void setRePassword(String rePassword) {
		this.rePassword = rePassword;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
